<?php

/**
 * Classe per la gestione di una query
 * @package    Query
 * @author    Domenico Biancardi <domenico.biancardi@gmail.com>
 * @link    http://code.google.com/p/syrius/
 *
 */
namespace Syrius\Adapter;

class Query {

    /**
     * Esegue una query
     * @param string $sql
     */
    public function __construct($sql) {
        if ($sql == "")
            return;
        if (\Syrius\Config\Config::getDebug())
            echo "<pre>$sql</pre>";
        $this->_driver = Connection::getConnection();
        $mysqlList = preg_split("/".\Syrius\Config\Config::getDelimiter()."/", $sql, -1, PREG_SPLIT_OFFSET_CAPTURE );
        for($i=0;$i<count($mysqlList);$i++){
            $this->_driver->real_query($mysqlList[$i][0]);
        }
        
        // viene scatenata un'eccezione se la precedente query da errore
        $this->error();
    }

    public function isMultiQuery($sql) {

    }

    /**
     * Get info about a last query
     */
    public function info() {
    }

    public function getInsertId() {
        return $this->_driver->insert_id;
    }

    public function getAffectedRow() {
    }

    public function getFieldCount() {
    }

    public function more_results() {
    }

    private $_driver;

    public function error() {
        if ($this->_driver->error != "") {
            echo $this->_driver->error;
            throw new \Syrius\Exception\Query ($this->_driver);
        }
    }

    public function getDriver() {
        return $this->_driver;
    }

    public function debug($active) {
        $this->_debug = $active;
    }

    private $_debug = false;

}

?>
